﻿using System;
using System.Collections.Generic;
using System.Web.Script.Services;
using System.Web.Services;
using WebApplication1.classes.Core.Chrome.Bookmarks.Wrapper;
using WebApplication1.classes.dataSources;

namespace WebApplication1.services {
    [WebService( Namespace = "http://tempuri.org/" )]
    [ScriptService]
    [Serializable]
    public class ChromeBookmarksService : WebService {
        const string WSBookmarkJSonFilePath = "s:\\Temp\\Google\\Chrome\\UserData\\Default\\Bookmarks.bak";

        private readonly BookmarkDatasource bookmarkDatasource_;

        public ChromeBookmarksService(){
            if ( bookmarkDatasource_ != null ) return;

            bookmarkDatasource_ = new BookmarkDatasource();
            bookmarkDatasource_.filePath = WSBookmarkJSonFilePath;
            bookmarkDatasource_.deserialize();
        }

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public IList<Bookmark> bookmarkChildListForItemPath( String itemPath) {
            return bookmarkDatasource_.bookmarkChildListForItemPath(itemPath);
        }

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
        public string bookmarkJsTreeForItemPath(String itemPath) {
            
            return bookmarkDatasource_.bookmarkJsTreeForItemPath(itemPath);
        } 

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public IList<Bookmark> bookmarkParentListForItemPath( String itemPath ) {
            return bookmarkDatasource_.bookmarkParentListForItemPath(itemPath);
        }
    }
}
